package y24.m3;

import java.util.Arrays;

public class Test4 {
    static class Solution {
        public int[] plusOne(int[] digits) {
            int l = digits.length;
            if (l == 1){
                if (digits[0] == 9){
                    int[] arr = {1,0};
                    return arr;
                }
            }
            for (int i = l - 1; i >= 0 ; i--) {
                digits[i] += 1;
                if (digits[i] < 10){
                    return digits;
                }
                digits[i] = 0;
            }
            int[] arr = new int[l+1];
            arr[0] = 1;
            for (int i = 1; i < l+1; i++) {
                arr[i] = digits[i-1];
            }
            return arr;
        }
    }
    public static void main(String[] args) {
        int[] arr1 = {1,2,3,9};
        System.out.println(Arrays.toString(new Solution().plusOne(arr1)));
        int[] arr2 = {9};
        System.out.println(Arrays.toString(new Solution().plusOne(arr2)));
        int[] arr3 = {1,2,9,9};
        System.out.println(Arrays.toString(new Solution().plusOne(arr3)));
        int[] arr4 = {9,9,9,9};
        System.out.println(Arrays.toString(new Solution().plusOne(arr4)));


    }
}
